package mvp.com.bbc.myfarm.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

import mvp.com.bbc.myfarm.R;
import mvp.com.bbc.myfarm.ui.GlideImageLoader;
import mvp.com.bbc.myfarm.ui.SpaceItemDecoration;
import mvp.com.bbc.myfarm.ui.adapter.HomeAdapter;

/**
 * author by ${cbf} on 2017/12/28.
 * changbfa@163.com
 */

public class HomeFragment extends Fragment {

    private View view;
    private RecyclerView rvHome;
    private Banner banner;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = LayoutInflater.from(container.getContext()).inflate(R.layout.fragment_list, container, false);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        rvHome = (RecyclerView) view.findViewById(R.id.recyclerview);
        banner = (Banner) view.findViewById(R.id.banner);
        LinearLayoutManager ll = new LinearLayoutManager(getContext());
        ll.setOrientation(LinearLayoutManager.HORIZONTAL);//设置水平方向
        rvHome.setLayoutManager(ll);
        int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.space);
        rvHome.addItemDecoration(new SpaceItemDecoration(spacingInPixels));
        HomeAdapter adapter = new HomeAdapter();
        rvHome.setAdapter(adapter);
        banner.setIndicatorGravity(BannerConfig.CENTER);
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        banner.setDelayTime(3000);
        banner.isAutoPlay(true);
        List<Integer> list = new ArrayList<>();
        list.add(R.drawable.benlers);
        list.add(R.drawable.benlers);
        list.add(R.drawable.benlers);
        list.add(R.drawable.benlers);
        banner.setImages(list).setImageLoader(new GlideImageLoader()).start();
    }
}
